package com.jz.community.moduleauthorization.register.presenter;

import com.jz.community.basecomm.mvp.BaseLifeCyclePresent;
import com.jz.community.basecomm.net.rxandroid.OnLoadListener;
import com.jz.community.basecomm.utils.LoggerUtils;
import com.jz.community.basecomm.utils.Preconditions;
import com.jz.community.basecomm.utils.WpToast;
import com.jz.community.basecomm.bean.LoginInfo;
import com.jz.community.moduleauthorization.register.bean.RegisterInfo;
import com.jz.community.moduleauthorization.register.model.RegisterModel;
import com.jz.community.moduleauthorization.register.model.RegisterModelImpl;
import com.jz.community.moduleauthorization.register.ui.RegisterView;

import java.util.HashMap;

/**
 * Created by Tony.Fan on 2018/3/20 15:58
 */
public class RegisterPresenter extends BaseLifeCyclePresent<RegisterView.View> implements RegisterView.Presenter {

    private RegisterView.View mView;
    private RegisterModel registerModel;

    public RegisterPresenter(RegisterView.View view) {
        mView = view;
        registerModel = new RegisterModelImpl(view.getContext());
    }

    @Override
    public void setPresenter(RegisterView.View v) {
        super.setPresenter(v);
    }

    @Override
    public void getRegisterInfo(HashMap<String, String> map) {

        registerModel.requestRegisterInfo(map, new OnLoadListener<RegisterInfo>() {
            @Override
            public void onSuccess(RegisterInfo registerInfo) {
                mView.showRegisterInfo(registerInfo);
            }

            @Override
            public void onFail(String s, int code) {
                if (!Preconditions.isNullOrEmpty(s)) {
                    WpToast.l(mView.getContext(), s);
                    mView.showError();
                }
            }
        });
    }

    @Override
    public void getLoginInfo(String mobi, String password, String loginType, String params, String deviceId, String registrationId) {
        registerModel.requestLoginInfo(mobi, password, loginType, params, deviceId, registrationId, new OnLoadListener<LoginInfo>() {
            @Override
            public void onSuccess(LoginInfo loginInfo) {
                mView.showLoginInfo(loginInfo);
            }

            @Override
            public void onFail(String s, int code) {

            }
        });
    }

    @Override
    public void getLoginSmsCode(String mobi, String type) {
        registerModel.requestGetSmsCode(mobi, type, new OnLoadListener<LoginInfo>() {
            @Override
            public void onSuccess(LoginInfo baseResponseInfo) {
                mView.showSmsCodeInfo(baseResponseInfo);
            }

            @Override
            public void onFail(String s, int code) {

            }
        });
    }
}
